﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TitleList.aspx.cs" Inherits="background.Manager.Enterprise.Forms.TitleList" %>

<!DOCTYPE html>
<% Hashtable ht=new Hashtable();
   ht.Add("text", "普通文本");
   ht.Add("radio", "单选");
   ht.Add("checkbox", "复选");
   ht.Add("date", "日历");
   ht.Add("upload", "上传");
   ht.Add("full", "图文文本");
   ht.Add("textarea", "文本域");
   
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>获取题目</title>
    <link href="../../Styles/index.css" rel="stylesheet" />
    <script src="../../Scripts/jquery-1.8.2.min.js"></script>
    <script src="../../Scripts/layer/layer.js"></script>

    <script type="text/javascript">
        function changeTemp(obj) {
            var _data = "";
            if ($(obj).attr("data-type") == "checkbox") {
                _data = $(obj).is(":checked") ? 1 : 0;
            } else {
                _data = $(obj).val();
            }
            $.post("Action/Temp.ashx", {
                action: "changeTemp",
                colm: $(obj).attr("data-colm"),
                data: _data,
                id: $(obj).attr("data-id")
            }, function (ret) {
                if (!ret) {
                    layer.msg("设置失败,稍后重试");
                    if ($(obj).attr("data-type") == "checkbox") {
                        if ($(obj).is(":checked")) { $(obj).removeAttr("checked") } else { $(obj).attr("checked", "checked") }
                    }
                }
            })
        }
        function massDelete() {
            var d = new Array();
            $("input[name='idbox']:checked").each(function () { d.push($(this).val()); })
            if (d.length == 0) { layer.msg("请选择要删除的项"); return; }
            if (confirm("确定要删除所选项吗？")) {
                $.post("Action/Temp.ashx", { action: "deleteTemp",GroupId:"<%=Request["groupid"]%>", idList: d.join(',') }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function deletes(id) {
            if (confirm("确定要删除吗？")) {
                $.post("Action/Temp.ashx", { action: "deleteTemp",GroupId:"<%=Request["groupid"]%>", idList: id }, function (ret) {
                    if (ret) {
                        layer.msg("删除成功，2秒后自动刷新页面", { icon: 1, time: 2000 }, function () { window.location.reload(); });
                    } else {
                        layer.msg("对不起删除失败，稍后再试", { icon: 2 });
                    }
                })
            }
        }
        function checkboxAll(obj) {
            $("input[name='idbox']").attr("checked", $(obj).is(":checked"));
        }

        var mt={
            update:function(_type,_id,_htmlname){
                $.getJSON("Action/Temp.ashx",{action:"getTemp",id:_id},function(json){
                    var h=new Array(),_area=[],son=json[0];
                    h.push('<table id="text" border="0" cellpadding="0" cellspacing="0" class="table">');
                    h.push('<tr><th>名称</th><td>');
                    h.push('<input type="text" id="txt" class="text" value="'+son.Title+'" /><label><input type="checkbox" value="" '+(son.Required=="True"?'checked="checked"':"")+' />必填</label>');
                    h.push('</td></tr>');
                    switch (_type) {
                        case "text":
                            _area=['480px', '250px'];
                            h.push('<tr><th>正则</th><td>');
                            h.push('<input type="text" id="Regx" class="text" value="'+son.Regx+'" placeholder="空则用户在提交数据时不进行任何验证" />');
                            h.push('</td></tr>');
                            break;
                        case "date":
                            _area=['480px', '250px'];
                            h.push('<tr><th>格式</th><td>');
                            h.push('<input type="text" id="format" class="text" value="'+son.Regx+'" />');
                            h.push('</td></tr>');
                            break;
                        case "full":
                        case "textarea":
                        case "upload":
                            _area=['480px', '190px'];
                            break;
                        case "radio":
                        case "checkbox":
                            _area=['480px', '470px'];
                            var ar=son.Data.split('&^');
                            h.push('<tr><th></th><td style="line-height: 20px"><p>');
                            h.push('A：<input type="text" class="text radio" data-type="A" value="'+(son.Data.length>0?ar[0].substr(1):"")+'" style="width: 256px" /><i>例：1</i>');
                            h.push('</p><p>');
                            h.push('B：<input type="text" class="text radio" data-type="B" value="'+(son.Data.length>0?ar[1].substr(1):"")+'" style="width: 256px" /><i>例：-1</i>');
                            h.push('</p><p>');
                            h.push('C：<input type="text" class="text radio" data-type="C" value="'+(son.Data.length>0?ar[2].substr(1):"")+'" style="width: 256px" /><i>例：2</i>');
                            h.push('</p><p>');
                            h.push('D：<input type="text" class="text radio" data-type="D" value="'+(son.Data.length>0?ar[3].substr(1):"")+'" style="width: 256px" /><i>例：5</i>');
                            h.push('</p><p>');
                            h.push('E：<input type="text" class="text radio" data-type="E" value="'+(son.Data.length>0?ar[4].substr(1):"")+'" style="width: 256px" />');
                            h.push('</p><p>');
                            h.push('F：<input type="text" class="text radio" data-type="F" value="'+(son.Data.length>0?ar[5].substr(1):"")+'" style="width: 256px" />');
                            h.push('</p></td></tr>');
                            break;
                    }
                    h.push('<tr><th>是否显示</th><td><label><input type="radio" name="state" value="1" '+(son.Display=="True"?'checked="checked"':"")+'  />是</label>&nbsp;&nbsp;');
                    h.push('<label><input type="radio" name="state" value="0" '+(son.Display=="False"?'checked="checked"':"")+'/>否</label>&nbsp;</td></tr>');
                    h.push("</table>");
                    layer.open({
                        type: 1,
                        title: "更新，"+_htmlname+"控件",
                        area: _area,
                        btn: ["保存"],
                        content: h.join(''),
                        yes:function(){
                            var _name = $("#txt");
                            if ($.trim(_name.val()).length == 0) { layer.msg("请输入控件显示的名称"); _name.focus(); return; }
                            var arr = new Array();
                            if(_type=="radio"||_type=="radio"){
                                var len = $(".radio[value!='']").length;
                                if (len < 2) { layer.msg("最少设置2个选项"); return; }
                                $(".radio").each(function () {
                                    arr.push($(this).attr("data-type") + $(this).val());
                                })
                            }
                            var _regx="";
                            if(_type=="text"){
                                _regx=$("#Regx").val();
                            }else if (_type=="date"){
                                _regx=$("#format").val();
                            }else{
                                _regx="";
                            }

                            $.post("Action/Temp.ashx", {
                                action:"changeTemps",
                                title:_name.val(),
                                list:arr.join('&^'),
                                display:$("input[name=state]:checked").val(),
                                required: $("#text input[type=checkbox]").is(":checked") ? 1 : 0,
                                regx:_regx,
                                id:_id
                            }, function (ret) {
                                if (ret == "True") {
                                    $("#tCount").text(Number($("#tCount").text()) + 1).show();
                                    layer.msg("恭喜您更新成功", { icon: 1, time: 2000 }, function () {
                                        window.location.reload();
                                    })
                                } else {
                                    layer.msg("对不起更新失败", { icon: 2, time: 2000 })
                                }
                            })
                        }
                    });
                })
            }
        }

    </script>
</head>
<body>
    <div class="top">
        <strong>控件管理</strong>
        <span style="float: right"><a href="javascript:history.back();">
            <img src="../../Images/bak.png" />后退</a></span>
    </div>
    <div class="main">
        <div>
            <div class="tool_search">
                <input type="button" class="sbtn" value="添加" onclick="window.location.href = 'AddTemp.aspx?groupid=<%=Request["groupid"]%>    '" />&nbsp;&nbsp;<input type="button" class="sbtn" value="批量删除" onclick="    massDelete()" />
            </div>
            <table border="0" cellpadding="0" cellspacing="0" class="listtable">
                <tr>
                    <th class="th" style="width: 20px">
                        <input type="checkbox" onchange="checkboxAll(this)" /></th>
                    <th class="th">类型</th>
                    <th class="th">名称</th>
                    <th class="th">必填</th>
                    <th class="th">显示</th>
                    <th class="th" style="width: 40px">排序</th>
                    <th class="th">创建日期</th>
                    <th class="th thlast">操作</th>
                </tr>
                <%System.Data.DataTable dt= Codes.Forms.getTempList(Request["groupid"], int.Parse(string.IsNullOrEmpty(Request["p"])?"1":Request["p"]), 20); %>
                <%foreach(System.Data.DataRow dr in dt.Rows) {%>
                <tr>
                    <td class="td">
                        <input type="checkbox" name="idbox" value="<%=dr["id"] %>" /></td>
                    <td class="td"><%=ht[dr["Type"]] %></td>
                    <td class="td" style="line-height: 20px"><%=dr["Title"] %></td>
                    <td class="td txtcenter">
                        <input type="checkbox" onchange="changeTemp(this)" data-colm="Required" data-type="checkbox" data-id="<%=dr["id"] %>" <%=bool.Parse(dr["Required"].ToString())?"checked='checked'":"" %> /></td>
                    <td class="td txtcenter">
                        <input type="checkbox" onchange="changeTemp(this)" data-colm="Display" data-type="checkbox" data-id="<%=dr["id"] %>" <%=bool.Parse(dr["Display"].ToString())?"checked='checked'":"" %> /></td>
                    <td class="td" style="padding:0">
                        <input type="text" class="order" data-colm="Order" data-type="text" value="<%=dr["Order"] %>" data-id="<%=dr["id"] %>" onchange="changeTemp(this)" /></td>
                    <td class="td"><%=Codes.h.ManuTime(((DateTime)dr["addtime"]).ToString("yyyy/MM/dd HH:mm")) %></td>
                    <td class="td tdlast txtcenter">
                        <a href="javascript:mt.update('<%=dr["Type"] %>',<%=dr["id"] %>,'<%=ht[dr["Type"]] %>');">
                            <img src="../../Images/edit.png" class="tool_edit" />编辑</a>
                        <a href="javascript:void(0);" onclick="deletes(<%=dr["id"] %>)">
                            <img src="../../Images/delete.png" class="tool_delete" />删除</a></td>
                </tr>
                <% } %>
            </table>
            <div class="tcdPageCode"></div>
            <script src="../../Scripts/jquery.page.js"></script>
            <script>
                $(".tcdPageCode").createPage({
                    pageCount: '<%=Math.Ceiling((double)Codes.Forms.getTempListCount(Request["groupid"])/20)%>',
                    current: '<%=string.IsNullOrEmpty(Request["p"])?"1":Request["p"]%>',
                    backFn: function (p) {
                        window.location.href = "?p=" + p;
                    }
                });
            </script>
        </div>
    </div>
    <!--#include file='../../Include/footer.html'-->
</body>
</html>
